home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
checkchar.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
143 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* checkchar -
* Test a character outline for self intersections
*
* Paul Haeberli - 1990
*
* exports
*
int checkchar(fnt,c)
*
*/
#include "stdio.h"
#include "objfnt.h"
#include "vect.h"
#define MAXPOS 2000
static int nedge;
static float edge[MAXPOS][4];
static double triarea(p00,p01,p10)
vect *p00,*p01,*p10;
{
double tz;
tz = (p10->x - p00->x) * (p10->y + p00->y);
tz += (p00->x - p01->x) * (p00->y + p01->y);
tz += (p01->x - p10->x) * (p01->y + p10->y);
return tz;
}
static int linecrosses(e1,e2)
float *e1, *e2;
{
double a1, a2;
a1 = triarea(e1+0,e1+2,e2+0);
a2 = triarea(e1+0,e1+2,e2+2);
if((a1*a2)<0.0)
return 1;
else
return 0;
}
static int checkinter(e1,e2)
float *e1, *e2;
{
if(e1[0] == e2[0] && e1[1] == e2[1])
return 0;
if(e1[0] == e2[2] && e1[0] == e2[3])
return 0;
if(e1[2] == e2[0] && e1[3] == e2[1])
return 0;
if(e1[2] == e2[2] && e1[3] == e2[3])
return 0;
if(linecrosses(e1,e2) && linecrosses(e2,e1))
return 1;
return 0;
}
static void clearedge()
{
nedge = 0;
}
static void addedge(p1,p2)
short *p1, *p2;
{
if(nedge>=MAXPOS) {
fprintf(stderr,"Increase MAXPOS\n");
exit(1);
}
edge[nedge][0] = p1[0];
edge[nedge][1] = p1[1];
edge[nedge][2] = p2[0];
edge[nedge][3] = p2[1];
nedge++;
}
static int checkedge(c)
int c;
{
int i, j, n, bad;
bad = 0;
for(i=0; i<nedge; i++) {
if(edge[i][0] == edge[i][2] && edge[i][1] == edge[i][3]) {
fprintf(stderr,"char %d zero length edge %d\n",c,i,j);
bad++;
}
n = 0;
for(j=i; j<nedge; j++) {
if(edge[i][0] == edge[j][0] && edge[i][1] == edge[j][1])
n++;
if(checkinter(edge[i],edge[j])) {
fprintf(stderr,"char %d edge intersect %d with %d\n",c,i,j);
fprintf(stderr,"edge1: %f %f to %f %f\n",
edge[i][0],edge[i][1],edge[i][2],edge[i][3]);
fprintf(stderr,"edge2: %f %f to %f %f\n",
edge[j][0],edge[j][1],edge[j][2],edge[j][3]);
bad++;
}
}
if(n != 1) {
fprintf(stderr,"char %d coincident point %f %f n is %d\n",c,edge[i][0],edge[i][1],n);
bad++;
}
}
return bad;
}
int checkchar(fnt,c)
objfnt *fnt;
int c;
{
chardesc *cd;
cd = getchardesc(fnt,c);
if(!cd)
return;
if(cd->data) {
clearedge();
applytocharedges(fnt,c,addedge);
return checkedge(c);
}
return 0;
}